package com.ruoyi.web.controller.order;

import java.util.List;


import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.enums.InjectType;


import com.ruoyi.order.domain.OrderAllocation;
import com.ruoyi.order.service.IOrderAllocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单分配Controller
 *
 * @author testlove
 * @date 2021-07-08
 */
@RestController
@Api("订单分配")
@RequestMapping("/system/allocation")
public class OrderAllocationController extends BaseController
{
    @Autowired
    private IOrderAllocationService orderAllocationService;

    /**
     * 查询订单分配列表
     */
    @PreAuthorize("@ss.hasPermi('system:allocation:list')")
    @GetMapping("/list")
    @ApiOperation("查询订单分配")
    public TableDataInfo list(OrderAllocation orderAllocation)
    {
        startPage();
        List<OrderAllocation> list = orderAllocationService.selectOrderAllocationList(orderAllocation);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('system:allocation:id')")
    @GetMapping("/listId")
    @ApiOperation("查询订单分配id")
    public TableDataInfo list()
    {
        List<Integer> list = orderAllocationService.selectOrderAllocationListId();
        return getDataTable(list);
    }

    /**
     * 导出订单分配列表
     */
    @PreAuthorize("@ss.hasPermi('system:allocation:export')")
    @Log(title = "订单分配", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrderAllocation orderAllocation)
    {
        List<OrderAllocation> list = orderAllocationService.selectOrderAllocationList(orderAllocation);
        ExcelUtil<OrderAllocation> util = new ExcelUtil<OrderAllocation>(OrderAllocation.class);
        return util.exportExcel(list, "订单分配数据");
    }

    /**
     * 获取订单分配详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:allocation:query')")
    @GetMapping(value = "/{orderAllocationId}")
    public AjaxResult getInfo(@PathVariable("orderAllocationId") Long orderAllocationId)
    {
        return AjaxResult.success(orderAllocationService.selectOrderAllocationById(orderAllocationId));
    }

    /**
     * 新增订单分配
     */
    @PreAuthorize("@ss.hasPermi('system:allocation:add')")
    @Log(title = "订单分配", businessType = BusinessType.INSERT)
    @PropertyInject(type = InjectType.Insert)
    @PostMapping
    @ApiOperation("新增订单分配")
    public AjaxResult add(@RequestBody OrderAllocation orderAllocation)
    {
        return toAjax(orderAllocationService.insertOrderAllocation(orderAllocation));
    }

    /**
     * 修改订单分配
     */
    @PropertyInject(type = InjectType.Update)
    @PreAuthorize("@ss.hasPermi('system:allocation:edit')")
    @Log(title = "订单分配", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改订单分配")
    public AjaxResult edit(@RequestBody OrderAllocation orderAllocation)
    {
        return toAjax(orderAllocationService.updateOrderAllocation(orderAllocation));
    }

    /**
     * 删除订单分配
     */
    @PreAuthorize("@ss.hasPermi('system:allocation:remove')")
    @Log(title = "订单分配", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderAllocationIds}")
    @ApiOperation("删除订单分配")
    public AjaxResult remove(@PathVariable Long[] orderAllocationIds)
    {
        return toAjax(orderAllocationService.deleteOrderAllocationByIds(orderAllocationIds));
    }
}
